package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MaterialPackegeMapper;
import com.ruoyi.system.domain.MaterialPackege;
import com.ruoyi.system.service.IMaterialPackegeService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-20
 */
@Service
public class MaterialPackegeServiceImpl extends ServiceImpl<MaterialPackegeMapper,MaterialPackege>implements IMaterialPackegeService
{
    @Autowired
    private MaterialPackegeMapper materialPackegeMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public MaterialPackege selectMaterialPackegeById(Long id)
    {
        return materialPackegeMapper.selectMaterialPackegeById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param materialPackege 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<MaterialPackege> selectMaterialPackegeList(MaterialPackege materialPackege,Integer pageNum,Integer pageSize)
    {
        LambdaQueryWrapper<MaterialPackege> queryWrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(materialPackege.getMaterial())){
            queryWrapper.like(MaterialPackege::getMaterial,materialPackege.getMaterial());
        }
        if(StringUtils.isNotBlank(materialPackege.getTag())){
            queryWrapper.like(MaterialPackege::getTag,materialPackege.getTag());
        }
        List<MaterialPackege> materialPackegeList = materialPackegeMapper.selectPage(new com.baomidou.mybatisplus.extension.plugins.pagination.Page(pageNum,pageSize),queryWrapper).getRecords();
        return materialPackegeList;
    }
    @Override
    public List<MaterialPackege> selectMaterialPackegeAll(MaterialPackege materialPackege)
    {
        return materialPackegeMapper.selectMaterialPackegeList(materialPackege);
    }

    @Override
    public Long selectMaterialPackegeCount(MaterialPackege materialPackege) {
        LambdaQueryWrapper<MaterialPackege> queryWrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(materialPackege.getMaterial())){
            queryWrapper.like(MaterialPackege::getMaterial,materialPackege.getMaterial());
        }
        if(StringUtils.isNotBlank(materialPackege.getTag())){
            queryWrapper.like(MaterialPackege::getTag,materialPackege.getTag());
        }
        return materialPackegeMapper.selectCount(queryWrapper);
    }


    /**
     * 新增【请填写功能名称】
     * 
     * @param materialPackege 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertMaterialPackege(MaterialPackege materialPackege)
    {
        return materialPackegeMapper.insertMaterialPackege(materialPackege);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param materialPackege 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateMaterialPackege(MaterialPackege materialPackege)
    {
        return materialPackegeMapper.updateMaterialPackege(materialPackege);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteMaterialPackegeByIds(Long[] ids)
    {
        return materialPackegeMapper.deleteMaterialPackegeByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteMaterialPackegeById(Long id)
    {
        return materialPackegeMapper.deleteMaterialPackegeById(id);
    }

    public MaterialPackege selectMaterialPackegeByIngreNoAndTag(String ingreNo,String tag){
        LambdaQueryWrapper<MaterialPackege> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MaterialPackege::getTag,tag);
        queryWrapper.eq(MaterialPackege::getMaterial,ingreNo);
        MaterialPackege materialPackege = materialPackegeMapper.selectOne(queryWrapper);
        return materialPackege;
    }
}
